package com.youle.service;

import com.youle.enums.ExceptionEnum;
import com.youle.exception.YLException;
import com.youle.item.pojo.Sku;
import com.youle.mapper.SkuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Created by
 *
 * @author touni
 * @date 2019/4/22
 * @time 18:30
 */
@Service
public class ItemSkuService {

    @Autowired
    private SkuMapper skuMapper;


    public ResponseEntity listSkuBySpuId(Long id) {
        Sku sku = new Sku();
        sku.setSpuId(id);
        List<Sku> skuList = this.skuMapper.select(sku);
        if (CollectionUtils.isEmpty(skuList)){ throw new YLException(ExceptionEnum.NOT_FOUND); }
        return ResponseEntity.status(HttpStatus.ACCEPTED).body(skuList);
    }
}
